package edu.lingnan.house.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.lingnan.house.mapper.BookMapper_lxj;
import edu.lingnan.house.pojo.TbBooking;
import edu.lingnan.house.pojo.TbHouse;
import edu.lingnan.house.service.BookService_lxj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookServiceImpl_lxj implements BookService_lxj {
    @Autowired
    public BookMapper_lxj bookMapper;

    //中介查询负责的未审批预约申请
    @Override
    public List<TbBooking> findBookByAgentIdAndState1(String agentId) {
        QueryWrapper<TbBooking> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("agent_id",agentId);
        queryWrapper.eq("state",1);
        List<TbBooking> list = bookMapper.selectList(queryWrapper);
        return list;
    }

    //中介查询负责的的已审批预约
    @Override
    public List<TbBooking> findBookByAgentIdAndState2(String agentId) {
        QueryWrapper<TbBooking> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("agent_id",agentId);
        queryWrapper.eq("state",2);
        List<TbBooking> list = bookMapper.selectList(queryWrapper);
        return list;
    }

    //中介审批通过客户预约申请
    @Override
    public int updateBookByAgent2(TbBooking booking) {
        if (booking == null || booking.equals("")){
            System.out.println("从浏览器得到的数据为空");
            return 0;
        }
        else {
            QueryWrapper<TbBooking> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", booking.getId());
            booking.setState(2);
            int row = bookMapper.update(booking, queryWrapper);
            return row;
        }
    }

    @Override
    public int updateBookByAgent4(TbBooking booking) {
        if (booking == null || booking.equals("")){
            System.out.println("从浏览器得到的数据为空");
            return 0;
        }
        else {
            QueryWrapper<TbBooking> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", booking.getId());
            booking.setState(4);
            int row = bookMapper.update(booking, queryWrapper);
            return row;
        }
    }
}
